<template>
  <div>
    <div id="selector">
      <table>
        <tr>
          <td style="width:33%">
            <button class="char_select_item" 
            :class="{char_selected : selectedIndex === 1}" @click="change(1)">柱状图</button>
          </td>
          <td style="width:34%">
            <button class="char_select_item" 
            :class="{char_selected : selectedIndex === 2}" @click="change(2)">折线图</button>
          </td>
          <td style="width:33%">
            <button class="char_select_item" 
            :class="{char_selected : selectedIndex === 3}" @click="change(3)">饼图</button>
          </td>
        </tr>
      </table>
      <div class="sperator"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'chart-selector',
  data() {
    return {
      selectedIndex:1
    }
  },
  methods: {
    change(index) {
      this.selectedIndex = index;
      switch(index) {
        case 1:
          this.$router.push('bar');
          break;
        case 2:
          this.$router.push('line');
          break;
        case 3:
          this.$router.push('pie');
          break;
        default:
          this.$router.push('');
          break;
      }
    }
  },
}
</script>

<style>
#selector {
  width: 100%;
}
#selector table {
  width: 100%;
  text-align: center;
}
#selector button {
  width: 100%;
  font-size: 20px;
  background-color: white;
  margin: 0 5px;
  padding: 5px 0;
  outline:none;
}
#selector button:hover {
  color: #409EFF;
}
#selector .char_select_item {
  border: 0;
}
#selector .char_selected {
  color: #409EFF;
  border: 0;
  border-bottom: #409EFF solid 2px;
}
#selector .sperator {
  width: 100%;
  height: 3px;
  background-color: gainsboro;
  opacity: 0.5;
  position: relative;
  top: -2px;
}
</style>